﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SeaBattle.Domain.Abstract.Services;
using SeaBattle.UI.Web.Models;
using SeaBattle.Domain.Concrete.Services;
using SeaBattle.Domain.Abstract;

namespace SeaBattle.UI.Web.Controllers
{
    [Authorize]
    public class GameController : Controller
    {
        //
        // GET: /Game/

        IGameRepository gameRepository;
        IPlayerRepository playerRepository;

        public GameController(IGameRepository gameRepository, IPlayerRepository playerRepository)
        {
            this.gameRepository = gameRepository;
            this.playerRepository = playerRepository;
        }

        public ActionResult Index(int id)
        {

            var game = gameRepository.GetGame(id);

            var me = playerRepository.GetPlayer(User.Identity.Name);

            if (game.Opponent == null)
            {
                game.JoinOpponent(me);
            }

            return View(new GameViewModel { Game = game});
        }

        public ActionResult GameBoard()
        {
            return View("ChildActions/GameBoard");
        
        }

    }
}
